// 卖出价格需要大于买入价格
var maxProfit = function (prices) {
  let n = prices.length;
  let profit_in = 0 - prices[0];
  let profit_out = 0;
  for (let i = 1; i < n; i++) {
    profit_out = Math.max(profit_out, profit_in + prices[i]);
    // k = 1 时，及交易次数为 1 时，买入的利润都是 prices[i];
    profit_in = Math.max(profit_in, -prices[i]);
  }
  return profit_out;
}